package com.fushenlan.epidemicControl.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fushenlan.Vo.EmergencyInfoVo;
import com.fushenlan.Vo.WorkBenchDetailVO;
import com.fushenlan.Vo.WorkbenchNucleinVO;
import com.fushenlan.epidemicControl.dto.EmergencyInfoDto;
import com.fushenlan.po.Emergency;
import com.fushenlan.po.EmergencyInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Author jiajia
 * @DATE 2022/4/21
 * @PACKAGE_NAME com.fushenlan.epidemicControl.mapper
 * @VERSION 1.0
 */
@Mapper
public interface EmergencyMapper extends BaseMapper<Emergency> {

    /**
     * 统计待处理救助总计
     * @return
     */
    @Select("SELECT count( 1 ) FROM  emergency t,inhabitant_info t2   WHERE t.state=1  and t.user_id=t2.Id \n" +
            "and t2.neighborhoodId=#{neighborhoodId}")
    int countPending(String neighborhoodId);

    /**
     *  根据小区id查详情
     * @param id 小区id
     * @return
     */
    @Select("SELECT buildingId, COUNT(case when t2.health_status=1 then 1  else null end ) yang_num,\n" +
        "COUNT(case when t2.user_status=1 then 1  else null end ) no_transport_num,\n" +
        "COUNT(case when t2.user_status=2 then 1  else null end ) transport_num,\n" +
        "COUNT(case when t2.user_status=3 then 1  else null end ) cure_num,\n" +
        "(select name from building_info where id=buildingId) building_name\n" +
        "FROM inhabitant_info t ,\n" +
        "nuclein_detection_abnormal_personnel t2 \n" +
        "WHERE t.id=t2.user_id \n" +
        "and  residentialId=#{id} \n" +
        "and t.neighborhoodId=#{neighborhoodId}\n"+
        "GROUP BY buildingId")
    List<WorkBenchDetailVO > workbenchDetail(long id,String neighborhoodId);

 /**
  *  info
  * @return
  */
    @Select(" SELECT DISTINCT t1.id ,\n" +
            "        t1.`name` ,\n" +
            "        count( CASE WHEN t3.user_status = 1 THEN 1 ELSE NULL END ) not_transport_num,-- 未转运\n" +
            "        count( CASE WHEN t3.user_status = 2 THEN 1 ELSE NULL END ) transport_num,-- 已转运\n" +
            "       COUNT(CASE WHEN t3.user_status = 3 THEN 1  ELSE NULL END ) cure_num,\n" +
            "        count( CASE WHEN t3.health_status = 1 THEN 1 ELSE NULL END )  yang_num -- 阳性\n" +
            "        FROM\n" +
            "        building_info t1,\n" +
            "        inhabitant_info t2,\n" +
            "        nuclein_detection_abnormal_personnel t3\n" +
            "        WHERE t1.id = t2.residentialId\n" +
            "        AND t2.id = t3.user_id\n" +
            "         and t2.neighborhoodId=#{neighborhoodId}\n"+
            "        GROUP BY\n" +
            "        t2.residentialId;\n")
    List<WorkbenchNucleinVO> workbenchInfo(String neighborhoodId);


    /**
     * 统计待转运总计
     * @return
     */
    @Select("SELECT count( 1 ) FROM  nuclein_detection_abnormal_personnel t\n" +
            ",inhabitant_info t2\n" +
            "WHERE\n" +
            "t.user_id=t2.id and\n" +
            "t.user_status=1 and\n" +
            "t2.neighborhoodId=#{neighborhoodId}")
    int countTransport(String neighborhoodId);

    /**
     * 根据居委和紧急程度，完成状态查询
     * @param map
     * @return
     */
    List<Emergency> findAllEmergencyList(Map<String,String> map);
}
